#include <string>
#include <iostream>
#include <fstream>

#include "cipher.h"
#include "library/playfair.h"
#include "library/rot13.h"
#include "library/vigenere.h"
using std::string;

void cipher(){
	int requesttype = getrequesttype();
	if (requesttype==0){
		int cipher= getcipher();
		if (cipher==0){
			Playfair x;
			std::cout << "What is your message? (no punctuation)" <<std::endl;
			std::cout << "Which version are you using?" << std::endl;
			x.message= getmessage();
			x.removeAllWhite(x.message);
			x.handleuppercase(x.message);
			x.handledouble(x.message);
			x.handleodd(x.message);
			std::cout << x.getletterpairs(x.message) << std::endl;
		}
		if (cipher==1){
			Caesar x;
			std::cout << "What is your message? (no punctuation)" << std::endl;
			x.message= getmessage();
		}
		if (cipher==2){
			Substitution x;
			std::cout << "What is your message? (no punctuation)" << std::endl;
		}
	}	
	if (requesttype==1){
		int cipher= getcipher();
		string filename = getfilename();
		string answerfilename = answerfilename(filename);
		ifstream infile (filename);
		ofstream outfile (answerfilename);
		if (infile.is_open())
		{
		  	if (outfile.is_open())
		  	{
				while (! infile.eof() )
		   		{
					string line;
				   	getline (myfile,line);
					if (cipher==1){Playfair x (line);}
					if (cipher==2){Caesar x (line);}
					if (cipher==3){Substitution x (line;)}
					x.solve();
					outfile << x.finalprep();
				}
			    infile.close();
				outfile.close();
			}
	  		else cout << "Unable to write to file";
		}
		else cout << "Unable to read from file"; 
	}
}

int main()
{
	if (getchar()){
		cipher();
	}	
}
	